package com.black.web.controller.upload;

import com.black.common.core.domain.R;
import com.black.common.utils.OSSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.io.IOException;

@Api(tags = "OSS对象存储Api")
@RestController
@RequestMapping("/oss")
public class OSSUploadController {
    @ApiOperation(value = "上传图片")
    @PostMapping("/uploadImg")
//    @ApiImplicitParam(name = "fatherPath", value = "父目录(所属模块)", dataType = "String", required = true)
    public R upload(@RequestPart("imgFile") MultipartFile file, @RequestParam("fatherPath") String fatherPath) throws IOException {
        return OSSUtils.uploadObjectOSS(fatherPath, file);
    }


    @ApiOperation(value = "删除图片")
    @PostMapping("/deleteImg")
    @ApiImplicitParam(name = "path", value = "图片路径", dataType = "String", required = true)
    public R delete(@RequestBody @Valid String path) {
        return OSSUtils.deleteFile(path);
    }

}
